package waebric.javacc;
public class WaebricParserVisitorAdapter implements WaebricParserVisitor
{	
	static final String EMPTY_STRING = "";
	static final String SPLIT_SEPARATOR = ":";
	
	static final String NODE_SIMPLENODE = "SimpleNode";
	static final String NODE_MODULES = "Modules";
    static final String NODE_MODULE = "Module";
    static final String NODE_MODULEID = "ModuleId";
    static final String NODE_MODULEELEMENT = "ModuleElement";
    static final String NODE_IMPORT = "Import";
    static final String NODE_SITE = "Site";
    static final String NODE_MAPPINGS = "Mappings";
    static final String NODE_MAPPING = "Mapping";
    static final String NODE_PATH = "Path";
    static final String NODE_FUNCTIONDEF = "FunctionDef";
    static final String NODE_FORMALS = "Formals";
    static final String NODE_STATEMENT = "Statement";
    static final String NODE_PREDICATE = "Predicate";
    static final String NODE_ASSIGNMENT = "Assignment"; 
    static final String NODE_EMBEDDING = "Embedding";
    static final String NODE_EMBED = "Embed";
    static final String NODE_TEXTTAIL = "TextTail";
    static final String NODE_MARKUP = "Markup";
    static final String NODE_DESIGNATOR = "Designator";
    static final String NODE_ATTRIBUTE = "Attribute";
    static final String NODE_ARGUMENTS = "Arguments";
    static final String NODE_ARGUMENT = "Argument";
    static final String NODE_VAR = "Var";
    static final String NODE_EXPRESSION = "Expression";
    static final String NODE_DOTIDCON = "DotIdCon";
    static final String NODE_KEYVALUEPAIR = "KeyValuePair";

	
	private String ast = EMPTY_STRING;
	
	/**
	 * @return retrieves the constructed AST from the node
	 */
	public String getAST(){
		return ast;
	}
	
	/**
	 * @param newAst: start a new AST.
	 */
	public void setAST(String newAst){
		ast = newAst;
	}
	
	/**
	 * @param stringToAdd: Add a string value to an already existing AST.
	 */
	public void addToAST(String stringToAdd){
		ast += stringToAdd;
	}
	
	/**
	 * @param stringArray: the string array you want to retrieve the string from
	 * @param index: index of the element you want the string from
	 * @return data from array when within bounds, otherwise an empty string
	 */
	protected String safeGetStr(String[] stringArray, int index){
		if (stringArray.length > index){
			return stringArray[index];
		} else {
			return EMPTY_STRING;
		}	
	}
	
	/**
	 * Method to retrieve last character of a string.
	 * @param inputStr: Subject string we want to know the last character of.
	 * @return last character of a string
	 */
	protected String lastCharacter(String inputStr){
		if (inputStr.length() > 0){
			return inputStr.substring(inputStr.length() -1, inputStr.length());
		} else {
			return EMPTY_STRING;
		}
	}
		
	/**
	 * Method to reconstruct text that has been split up using split.
	 * @param textElements: String array with elements that have been split by the colon
	 * @param startIndex: integer that marks the first array element of textElements.
	 * @param separator: String that is placed between array elements.
	 * @return reconstructed text which includes the separator(s).
	 */
	protected String reconstructText(String[] textElements, int startIndex, String separator){
		String reconstructedText = EMPTY_STRING;
		for (int textElementIndex = startIndex; textElementIndex < textElements.length; textElementIndex++){
			
			if (textElementIndex > startIndex){
				reconstructedText += separator;
			}
			reconstructedText += safeGetStr(textElements, textElementIndex);
		}
		return reconstructedText;
	}
	
	/**
	 * Adds quotes to both sides of the string
	 * @param stringToQuote: String that needs quotes
	 * @return "\"" + stringToQuote + "\""
	 */
	protected String addQuotes(String stringToQuote){
		return "\"" + stringToQuote + "\"";
	}
	
	/**
	 * Adds escaped quotes to both sides of the string
	 * @param stringToQuote: String that needs escaped quotes
	 * @return "\"\\\"" + stringToQuote + "\\\"\""
	 */
	protected String addEscQuotes(String stringToQuote){
		return "\"\\\"" + stringToQuote + "\\\"\"";
	}
	
	/* 
	 * All methods below are required by the code generated by JJTree to support the ASTVisitor descendants
	 * even if left unused.
	 */
	public Object visit(SimpleNode node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTModules node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTModule node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTModuleId node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTModuleElement node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTImport node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTSite node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTMappings node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTMapping node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTPath node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTFunctionDef node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTFormals node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTStatement node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTPredicate node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTAssignment node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTEmbedding node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTEmbed node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTTextTail node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTMarkup node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTDesignator node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTAttribute node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTArguments node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTArgument node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTVar node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTExpression node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTDotIdCon node, Object data){
		return node.childrenAccept(this, data);
	}
	
	public Object visit(ASTKeyValuePair node, Object data){
		return node.childrenAccept(this, data);
	}
}
